package com.ruoyi.report_sn.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.syrw.annotation.FIllBasicInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.report_sn.domain.bo.SnbzjcjlbBsInfoBo;
import com.ruoyi.report_sn.domain.vo.SnbzjcjlbBsInfoVo;
import com.ruoyi.report_sn.domain.SnbzjcjlbBsInfo;
import com.ruoyi.report_sn.mapper.SnbzjcjlbBsInfoMapper;
import com.ruoyi.report_sn.service.ISnbzjcjlbBsInfoService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 水泥标准稠度用水量、凝结时间、安定性试验检测记录Service业务层处理
 *
 * @author Li lb
 * @date 2024-05-10
 */
@RequiredArgsConstructor
@Service
public class SnbzjcjlbBsInfoServiceImpl implements ISnbzjcjlbBsInfoService {

    private final SnbzjcjlbBsInfoMapper baseMapper;

    /**
     * 查询水泥标准稠度用水量、凝结时间、安定性试验检测记录
     */
    @Override
    @FIllBasicInfo
    public SnbzjcjlbBsInfoVo queryById(Long excelId){
        return baseMapper.selectVoById(excelId);
    }

    /**
     * 查询水泥标准稠度用水量、凝结时间、安定性试验检测记录列表
     */
    @Override
    public TableDataInfo<SnbzjcjlbBsInfoVo> queryPageList(SnbzjcjlbBsInfoBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<SnbzjcjlbBsInfo> lqw = buildQueryWrapper(bo);
        Page<SnbzjcjlbBsInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询水泥标准稠度用水量、凝结时间、安定性试验检测记录列表
     */
    @Override
    public List<SnbzjcjlbBsInfoVo> queryList(SnbzjcjlbBsInfoBo bo) {
        LambdaQueryWrapper<SnbzjcjlbBsInfo> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<SnbzjcjlbBsInfo> buildQueryWrapper(SnbzjcjlbBsInfoBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<SnbzjcjlbBsInfo> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getPage() != null, SnbzjcjlbBsInfo::getPage, bo.getPage());
        lqw.eq(bo.getTotalPage() != null, SnbzjcjlbBsInfo::getTotalPage, bo.getTotalPage());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancdwmc()), SnbzjcjlbBsInfo::getJiancdwmc, bo.getJiancdwmc());
        lqw.eq(StringUtils.isNotBlank(bo.getJilbh()), SnbzjcjlbBsInfo::getJilbh, bo.getJilbh());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcmc()), SnbzjcjlbBsInfo::getGongcmc, bo.getGongcmc());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcbwyt()), SnbzjcjlbBsInfo::getGongcbwyt, bo.getGongcbwyt());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpmc()), SnbzjcjlbBsInfo::getYangpmc, bo.getYangpmc());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpbh()), SnbzjcjlbBsInfo::getYangpbh, bo.getYangpbh());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpsl()), SnbzjcjlbBsInfo::getYangpsl, bo.getYangpsl());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpzt()), SnbzjcjlbBsInfo::getYangpzt, bo.getYangpzt());
        lqw.eq(bo.getYangpsj() != null, SnbzjcjlbBsInfo::getYangpsj, bo.getYangpsj());
        lqw.eq(StringUtils.isNotBlank(bo.getShiyjcrq()), SnbzjcjlbBsInfo::getShiyjcrq, bo.getShiyjcrq());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjwd()), SnbzjcjlbBsInfo::getShiytjwd, bo.getShiytjwd());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjsd()), SnbzjcjlbBsInfo::getShiytjsd, bo.getShiytjsd());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyj()), SnbzjcjlbBsInfo::getJiancyj, bo.getJiancyj());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyj()), SnbzjcjlbBsInfo::getPandyj, bo.getPandyj());
        lqw.eq(StringUtils.isNotBlank(bo.getZhuyyqsbmcjbh()), SnbzjcjlbBsInfo::getZhuyyqsbmcjbh, bo.getZhuyyqsbmcjbh());
        lqw.eq(bo.getBiaozcdyslsyzl() != null, SnbzjcjlbBsInfo::getBiaozcdyslsyzl, bo.getBiaozcdyslsyzl());
        lqw.eq(bo.getBiaozcdysljsl() != null, SnbzjcjlbBsInfo::getBiaozcdysljsl, bo.getBiaozcdysljsl());
        lqw.eq(bo.getBiaozcdyslsgxcdbjl() != null, SnbzjcjlbBsInfo::getBiaozcdyslsgxcdbjl, bo.getBiaozcdyslsgxcdbjl());
        lqw.eq(bo.getBiaozcdyslbzcdysl() != null, SnbzjcjlbBsInfo::getBiaozcdyslbzcdysl, bo.getBiaozcdyslbzcdysl());
        lqw.eq(StringUtils.isNotBlank(bo.getNingjsjksjssj()), SnbzjcjlbBsInfo::getNingjsjksjssj, bo.getNingjsjksjssj());
        lqw.eq(StringUtils.isNotBlank(bo.getChuncdsj1()), SnbzjcjlbBsInfo::getChuncdsj1, bo.getChuncdsj1());
        lqw.eq(StringUtils.isNotBlank(bo.getZhongncdsj1()), SnbzjcjlbBsInfo::getZhongncdsj1, bo.getZhongncdsj1());
        lqw.eq(StringUtils.isNotBlank(bo.getZhongncdhx1()), SnbzjcjlbBsInfo::getZhongncdhx1, bo.getZhongncdhx1());
        lqw.eq(StringUtils.isNotBlank(bo.getZhongncdsj2()), SnbzjcjlbBsInfo::getZhongncdsj2, bo.getZhongncdsj2());
        lqw.eq(StringUtils.isNotBlank(bo.getZhongncdhx2()), SnbzjcjlbBsInfo::getZhongncdhx2, bo.getZhongncdhx2());
        lqw.eq(StringUtils.isNotBlank(bo.getZhongncdsj3()), SnbzjcjlbBsInfo::getZhongncdsj3, bo.getZhongncdsj3());
        lqw.eq(StringUtils.isNotBlank(bo.getZhongncdhx3()), SnbzjcjlbBsInfo::getZhongncdhx3, bo.getZhongncdhx3());
        lqw.eq(StringUtils.isNotBlank(bo.getZhongncdsj4()), SnbzjcjlbBsInfo::getZhongncdsj4, bo.getZhongncdsj4());
        lqw.eq(StringUtils.isNotBlank(bo.getZhongncdhx4()), SnbzjcjlbBsInfo::getZhongncdhx4, bo.getZhongncdhx4());
        lqw.eq(StringUtils.isNotBlank(bo.getZhongncdsj5()), SnbzjcjlbBsInfo::getZhongncdsj5, bo.getZhongncdsj5());
        lqw.eq(StringUtils.isNotBlank(bo.getZhongncdhx5()), SnbzjcjlbBsInfo::getZhongncdhx5, bo.getZhongncdhx5());
        lqw.eq(StringUtils.isNotBlank(bo.getZhongncdsj6()), SnbzjcjlbBsInfo::getZhongncdsj6, bo.getZhongncdsj6());
        lqw.eq(StringUtils.isNotBlank(bo.getZhongncdhx6()), SnbzjcjlbBsInfo::getZhongncdhx6, bo.getZhongncdhx6());
        lqw.eq(StringUtils.isNotBlank(bo.getZhongncdsj7()), SnbzjcjlbBsInfo::getZhongncdsj7, bo.getZhongncdsj7());
        lqw.eq(StringUtils.isNotBlank(bo.getZhongncdhx7()), SnbzjcjlbBsInfo::getZhongncdhx7, bo.getZhongncdhx7());
        lqw.eq(StringUtils.isNotBlank(bo.getZhongncdsj8()), SnbzjcjlbBsInfo::getZhongncdsj8, bo.getZhongncdsj8());
        lqw.eq(StringUtils.isNotBlank(bo.getZhongncdhx8()), SnbzjcjlbBsInfo::getZhongncdhx8, bo.getZhongncdhx8());
        lqw.eq(StringUtils.isNotBlank(bo.getZhongncdsj9()), SnbzjcjlbBsInfo::getZhongncdsj9, bo.getZhongncdsj9());
        lqw.eq(StringUtils.isNotBlank(bo.getZhongncdhx9()), SnbzjcjlbBsInfo::getZhongncdhx9, bo.getZhongncdhx9());
        lqw.eq(StringUtils.isNotBlank(bo.getZhongncdsj10()), SnbzjcjlbBsInfo::getZhongncdsj10, bo.getZhongncdsj10());
        lqw.eq(StringUtils.isNotBlank(bo.getZhongncdhx10()), SnbzjcjlbBsInfo::getZhongncdhx10, bo.getZhongncdhx10());
        lqw.eq(StringUtils.isNotBlank(bo.getZhongncdsj11()), SnbzjcjlbBsInfo::getZhongncdsj11, bo.getZhongncdsj11());
        lqw.eq(StringUtils.isNotBlank(bo.getZhongncdhx11()), SnbzjcjlbBsInfo::getZhongncdhx11, bo.getZhongncdhx11());
        lqw.eq(bo.getNingjsjcnsj() != null, SnbzjcjlbBsInfo::getNingjsjcnsj, bo.getNingjsjcnsj());
        lqw.eq(bo.getNingjsjznsj() != null, SnbzjcjlbBsInfo::getNingjsjznsj, bo.getNingjsjznsj());
        lqw.eq(bo.getShibfzjrq() != null, SnbzjcjlbBsInfo::getShibfzjrq, bo.getShibfzjrq());
        lqw.eq(bo.getShibfcdrq() != null, SnbzjcjlbBsInfo::getShibfcdrq, bo.getShibfcdrq());
        lqw.eq(StringUtils.isNotBlank(bo.getShibfqk()), SnbzjcjlbBsInfo::getShibfqk, bo.getShibfqk());
        lqw.eq(StringUtils.isNotBlank(bo.getShibfqk2()), SnbzjcjlbBsInfo::getShibfqk2, bo.getShibfqk2());
        lqw.eq(StringUtils.isNotBlank(bo.getShibfcdjg()), SnbzjcjlbBsInfo::getShibfcdjg, bo.getShibfcdjg());
        lqw.eq(bo.getLeisfzjrq() != null, SnbzjcjlbBsInfo::getLeisfzjrq, bo.getLeisfzjrq());
        lqw.eq(bo.getLeisfcdrq() != null, SnbzjcjlbBsInfo::getLeisfcdrq, bo.getLeisfcdrq());
        lqw.eq(bo.getLeisfaz1() != null, SnbzjcjlbBsInfo::getLeisfaz1, bo.getLeisfaz1());
        lqw.eq(bo.getLeisfcz1() != null, SnbzjcjlbBsInfo::getLeisfcz1, bo.getLeisfcz1());
        lqw.eq(bo.getLeisfdanz1() != null, SnbzjcjlbBsInfo::getLeisfdanz1, bo.getLeisfdanz1());
        lqw.eq(bo.getLeisfaz2() != null, SnbzjcjlbBsInfo::getLeisfaz2, bo.getLeisfaz2());
        lqw.eq(bo.getLeisfcz2() != null, SnbzjcjlbBsInfo::getLeisfcz2, bo.getLeisfcz2());
        lqw.eq(bo.getLeisfdanz2() != null, SnbzjcjlbBsInfo::getLeisfdanz2, bo.getLeisfdanz2());
        lqw.eq(bo.getLeisfpingjz() != null, SnbzjcjlbBsInfo::getLeisfpingjz, bo.getLeisfpingjz());
        lqw.eq(StringUtils.isNotBlank(bo.getLeisfcdjg()), SnbzjcjlbBsInfo::getLeisfcdjg, bo.getLeisfcdjg());
        lqw.eq(StringUtils.isNotBlank(bo.getFujsm()), SnbzjcjlbBsInfo::getFujsm, bo.getFujsm());
        lqw.eq(StringUtils.isNotBlank(bo.getJianc()), SnbzjcjlbBsInfo::getJianc, bo.getJianc());
        lqw.eq(StringUtils.isNotBlank(bo.getJil()), SnbzjcjlbBsInfo::getJil, bo.getJil());
        lqw.eq(StringUtils.isNotBlank(bo.getFuh()), SnbzjcjlbBsInfo::getFuh, bo.getFuh());
        lqw.eq(bo.getRiq() != null, SnbzjcjlbBsInfo::getRiq, bo.getRiq());
        return lqw;
    }

    /**
     * 新增水泥标准稠度用水量、凝结时间、安定性试验检测记录
     */
    @Override
    public Boolean insertByBo(SnbzjcjlbBsInfoBo bo) {
        SnbzjcjlbBsInfo add = BeanUtil.toBean(bo, SnbzjcjlbBsInfo.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setExcelId(add.getExcelId());
        }
        return flag;
    }

    /**
     * 修改水泥标准稠度用水量、凝结时间、安定性试验检测记录
     */
    @Override
    public Boolean updateByBo(SnbzjcjlbBsInfoBo bo) {
        SnbzjcjlbBsInfo update = BeanUtil.toBean(bo, SnbzjcjlbBsInfo.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(SnbzjcjlbBsInfo entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除水泥标准稠度用水量、凝结时间、安定性试验检测记录
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
